<?php
return [
    'module' => [
        'name' => 'order_item',
        'title' => '订单商品',
        'table' => 'order_items',
    ],
    
    'fields' => [
        'id' => [
            'type' => 'bigint',
            'length' => 20,
            'comment' => '订单商品ID',
            'unsigned' => true,
            'nullable' => false,
            'primary' => true,
            'auto_increment' => true,
            'required' => true,
        ],
        'order_id' => [
            'type' => 'bigint',
            'length' => 20,
            'comment' => '订单ID',
            'unsigned' => true,
            'nullable' => false,
            'required' => true,
            'index' => true,
        ],
        'product_id' => [
            'type' => 'bigint',
            'length' => 20,
            'comment' => '商品ID',
            'unsigned' => true,
            'nullable' => false,
            'required' => true,
            'index' => true,
        ],
        'product_sku_id' => [
            'type' => 'bigint',
            'length' => 20,
            'comment' => '商品SKU ID',
            'unsigned' => true,
            'nullable' => false,
            'required' => true,
        ],
        'product_name' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '商品名称',
            'nullable' => false,
            'required' => true,
        ],
        'product_image' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '商品图片',
            'nullable' => false,
            'required' => true,
        ],
        'product_price' => [
            'type' => 'decimal',
            'length' => '10,2',
            'comment' => '商品单价',
            'nullable' => false,
            'required' => true,
            'default' => 0.00,
        ],
        'quantity' => [
            'type' => 'int',
            'length' => 11,
            'comment' => '购买数量',
            'nullable' => false,
            'required' => true,
            'default' => 0,
        ],
        'total_amount' => [
            'type' => 'decimal',
            'length' => '10,2',
            'comment' => '商品总价',
            'nullable' => false,
            'required' => true,
            'default' => 0.00,
        ],
        'sku_properties' => [
            'type' => 'json',
            'comment' => 'SKU属性',
            'nullable' => false,
            'required' => true,
        ],
        'created_at' => [
            'type' => 'timestamp',
            'comment' => '创建时间',
            'nullable' => false,
            'default' => 'CURRENT_TIMESTAMP',
            'raw_default' => true
        ],
        'updated_at' => [
            'type' => 'timestamp',
            'comment' => '更新时间',
            'nullable' => false,
            'default' => 'CURRENT_TIMESTAMP',
            'raw_default' => true,
            'extra' => 'ON UPDATE CURRENT_TIMESTAMP'
        ],
    ],
    
    'relations' => [
        'order' => [
            'type' => 'belongsTo',
            'model' => 'Order',
            'foreign_key' => 'order_id',
        ],
        'product' => [
            'type' => 'belongsTo', 
            'model' => 'Product',
            'foreign_key' => 'product_id',
        ],
        'sku' => [
            'type' => 'belongsTo',
            'model' => 'ProductSku',
            'foreign_key' => 'product_sku_id',
        ]
    ],
    
    'queries' => [
        'order_id' => ['=', '?'],
        'product_id' => ['=', '?'],
        'product_sku_id' => ['=', '?'],
        'created_at' => ['between', '?,?'],
    ],
];